package com.chookss.home.search.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chookss.R;
import com.chookss.base.BaseViewHolderEx;
import com.chookss.home.logContacts.LogDetailActivity;
import com.chookss.home.search.entity.SearchAllEntity;
import com.chookss.mine.personal.PersonalHomeActivity;
import com.chookss.tools.EntityUtils;
import com.chookss.tools.GlideUtils;
import com.chookss.tools.Utils;
import com.chookss.view.CircleImageView;

import java.util.List;

import io.reactivex.annotations.Nullable;

public class SearchDiaryAdapter extends BaseQuickAdapter<SearchAllEntity.DiaryBean.ListBean, BaseViewHolderEx> {
    private Context context;
    private int width, height;
    private String key;

    public SearchDiaryAdapter(int layoutResId, Context context, @Nullable List<SearchAllEntity.DiaryBean.ListBean> data) {
        super(layoutResId, data);
        this.context = context;

    }

    @Override
    protected void convert(BaseViewHolderEx helper, SearchAllEntity.DiaryBean.ListBean item) {
        TextView tvTiltle = helper.getView(R.id.tvSearchLogTitle);
        TextView tvSearchType = helper.getView(R.id.tvSearchLogContains);
        TextView tvSearchProvider = helper.getView(R.id.tvSearchLogProvider);
        CircleImageView ivSearchLog = helper.getView(R.id.ivSearchLog);
        GlideUtils.loadAvatar(context,  item.getHead_photo_thumb_url(), ivSearchLog);
        if(Utils.isNull(item.getHead_photo_thumb_url())){
            GlideUtils.loadAvatar(context,  item.getHeadPhotoUrl(), ivSearchLog);
        }else{
            GlideUtils.loadAvatar(context,  item.getHead_photo_thumb_url(), ivSearchLog);
        }
        tvTiltle.setText(Utils.matcherSearchTitle(context.getResources().getColor(R.color.main_color),item.getTitle(),key));
        tvSearchProvider.setText("发布人：");
        tvSearchProvider.append(Utils.matcherSearchTitle(context.getResources().getColor(R.color.main_color), item.getEmployeeName(),key));
        tvSearchType.setText("包含：");
        tvSearchType.append(Utils.matcherSearchTitle(context.getResources().getColor(R.color.main_color), item.getContent(),key));
        helper.getItemView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, LogDetailActivity.class);
                intent.putExtra("data", EntityUtils.modelA2B(item));
                intent.putExtra("title", item.getTitle());
                context. startActivity(intent);
            }
        });
        ivSearchLog.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, PersonalHomeActivity.class);
                intent.putExtra("employeeCode", item.getEmployeeCode());
                context. startActivity(intent);
            }
        });
    }

    public void setKey(String key){
        this.key=key;
    }
}
